const {
    src,
    dest,
    series,
    watch
} = require('gulp')
const less = require('gulp-less')
const rename = require('gulp-rename')
// const cssmin = require('gulp-clean-css');
function compileLess(path) {
    // 
    return function () {
        return src([`${path}**/*.less`, `!${path}**/_*.less`])
            .pipe(less())
            // .pipe(cssmin())
            // .pipe(cssmin())
            .pipe(
                rename((path) => {
                    // 
                    path.extname = '.wxss'
                    path.basename = `${path.basename}-min`
                })
            )
   
            .pipe(dest(() => {

                return path
            }))
    }

}

function watchLess(cb) {
    watch('./components/**/*.less', compileLess('./components/'));
    watch('./pages/**/*.less', compileLess('./pages/'));
    cb()
}
exports.default = series(
    compileLess('./components/'),
    compileLess('./pages/'),
    watchLess
)

/**
 * src()、dest()、series()、watch()、less()、rename()
 * compileLess()、watchLess()
 * 
 * 
 */